package com.liholin.springboot.sample.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liholin.springboot.sample.annotation.DataPermission;
import com.liholin.springboot.sample.bean.Member;
import com.liholin.springboot.sample.bean.SortMemberBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

@DataPermission
@Mapper
public interface MemberMapper extends BaseMapper<Member> {

    @Select({"<script>" +
            "SELECT * FROM t_member where 1=1" +
            "<if test='query != null and query.memberId != 0'>" +
            "AND memberId = #{query.memberId}" +
            "</if>" +
            "<if test='query != null and query.name != null'>" +
            "AND name like concat('%',#{query.name},'%')" +
            "</if>" +
            "<if test='query != null and query.age != 0'>" +
            "AND age= #{query.age}" +
            "</if>" +
            "<if test='query != null and query.email != null'>" +
            "AND email like concat('%',#{query.email},'%')" +
            "</if>" +
            "<if test='desc=1'>" +
            "order by #{sort} DESC" +
            "</if>"+
            "<if test='desc!=1'>" +
            "order by #{sort} asc" +
            "</if>"+
            "</script>"})
    IPage<Member> getSortMember(Page<Member> page, int desc, String sort, SortMemberBean query);


    @DataPermission
    @SelectProvider(type = ServiceBusinessMapperProvider.class,method = "selectServicePage")
    List<Member> selectServicePage(@Param("desc") int desc, @Param("sort") String sort,SortMemberBean query);

    @DataPermission
    @SelectProvider(type = ServiceBusinessMapperProvider.class,method = "selectServicePage")
    List<Member> selectServicePageSql(@Param("desc") int desc, @Param("sort") String sort,SortMemberBean query,String userId);

    @Select("SELECT * FROM t_member where memberId = #{id}")
    Member getMemberListJetCache(int id);
}
